package com.hkd.common.api.convert;

import com.hkd.common.api.SysException;
import com.hkd.common.api.enums.Status;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @author HKD
 * @date 2022/9/17 19:04
 */
@Component
public class StatusConvert implements Converter<Integer, Status> {
    @Override
    public Status convert(Integer source) {
        return Optional.ofNullable(Status.search(source)).orElseGet(() -> {
            throw new SysException("无此状态");
        });
    }
}
